unit uDiaBoxEdit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Buttons;

type
  TfDiaBoxEdit = class(TForm)
    RadioGroup1: TRadioGroup;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Edit1: TEdit;
    BitBtn2: TBitBtn;
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    BitBtn4: TBitBtn;
    GroupBox2: TGroupBox;
    Label4: TLabel;
    Edit3: TEdit;
    BitBtn3: TBitBtn;
    GroupBox3: TGroupBox;
    Label2: TLabel;
    ComboBox1: TComboBox;
    Edit2: TEdit;
    Label3: TLabel;
    Edit4: TEdit;
    procedure ComboBox1Change(Sender: TObject);
    procedure FormHide(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }     
  end;

var
  fDiaBoxEdit: TfDiaBoxEdit;

implementation

uses uDiaBoxMain, uEditScript, uEditText;

{$R *.dfm}

procedure TfDiaBoxEdit.ComboBox1Change(Sender: TObject);
begin
  Edit2.Visible := ComboBox1.ItemIndex = 1;
  if (ComboBox1.ItemIndex = 1) then Edit2.SetFocus;
end;

procedure TfDiaBoxEdit.FormHide(Sender: TObject);
begin
  fDiaBoxMain.SG.SetFocus;
end;

procedure TfDiaBoxEdit.BitBtn1Click(Sender: TObject);
begin
  with fDiaBoxMain do
  begin
    Saved := False;
    SG.Cells[0, SG.Row] := IntToStr(SG.Row + 1);
    if (RadioGroup1.ItemIndex = 0)
      then SG.Cells[1, SG.Row] := 'PC'
      else SG.Cells[1, SG.Row] := 'NPC';
    SG.Cells[2, SG.Row] := Edit1.Text;
    case ComboBox1.ItemIndex of
      0: SG.Cells[3, SG.Row] := '';
      1: SG.Cells[3, SG.Row] := Edit2.Text;
      2: SG.Cells[3, SG.Row] := '-1';
    end;
    if (Edit4.Text <> '') then SG.Cells[3, SG.Row] := SG.Cells[3, SG.Row] + '/' + Edit4.Text;
    SG.Cells[4, SG.Row] := Edit3.Text;
    if (SG.Row > Dialog.Count - 1) then Dialog.Append('');
    Dialog[SG.Row] := IntToStr(RadioGroup1.ItemIndex) + '|' + Edit1.Text + '|'
      + SG.Cells[3, SG.Row] + '|' + SG.Cells[4, SG.Row];
    UpdateText;  
  end;
end;

procedure TfDiaBoxEdit.BitBtn3Click(Sender: TObject);
var
  I: Integer;
  V: TExplodeResult;
begin
  V := fDiaBoxMain.Explode(string(';'), Edit3.Text);
  fEditScript.RE.Clear;
  for I := 0 to High(V) do
    if (Trim(V[I]) <> '') then
      fEditScript.RE.Lines.Append(Trim(V[I]) + ';');
  fEditScript.ShowModal;
end;

procedure TfDiaBoxEdit.BitBtn2Click(Sender: TObject);
begin
  fEditText.RE.Text := Edit1.Text;
  fEditText.ShowModal;
end;

end.
